home *** CD-ROM | disk | FTP | other *** search
/ Aminet 49 / Aminet 49 (2002)(GTI - Schatztruhe)[!][Jun 2002].iso / Aminet / util / misc / ReportPlus.lha / ReportPlus / source / f7.c < prev    next >
C/C++ Source or Header  |  2002-04-15  |  25KB  |  680 lines

  1. #include <exec/types.h>
  2. #include <exec/memory.h>
  3. #include <intuition/intuition.h>
  4. #include <intuition/gadgetclass.h>
  5. #include <libraries/gadtools.h>
  6. #include <dos/dosextens.h>
  7. #include <graphics/gfx.h>
  8.  
  9. #include <clib/exec_protos.h>
  10. #include <clib/intuition_protos.h>
  11. #include <clib/gadtools_protos.h>
  12. #include <clib/dos_protos.h>
  13. #include <clib/graphics_protos.h>
  14.  
  15. #define ALL_REACTION_CLASSES
  16. #define ALL_REACTION_MACROS
  17. #include <reaction/reaction.h>
  18.  
  19. #include <ctype.h>
  20. #include <stdlib.h>
  21. #include <string.h>
  22. #include "rp.h"
  23.  
  24. #define AMIGA 0
  25. #define MAC   1
  26. #define IBM   2
  27.  
  28. // from rp.c
  29. IMPORT TEXT                IOBuffer[LONGESTFIELD + 1];
  30. IMPORT ABOOL               fillwindows, stop;
  31. IMPORT SBYTE               page;
  32. IMPORT SWORD               y;
  33. IMPORT TEXT                asldir[VLONGFIELD + 1];
  34. IMPORT ULONG               fillcolour;
  35. IMPORT struct NewGadget    Gadget;
  36. IMPORT struct Window*      MainWindowPtr;
  37. IMPORT struct Screen*      ScreenPtr;
  38. IMPORT struct IconBase*    IconBase;
  39. IMPORT struct SharedStruct shared;
  40. IMPORT Object*             WinObject[FUNCTIONS + 1];
  41. IMPORT struct Menu*        MenuPtr;
  42.  
  43. MODULE struct
  44. {   ULONG detabulate, unwrap, source, dest, tabsize;
  45.     TEXT  pathname[VLONGFIELD + 1];
  46. } eol =
  47. {   FALSE, FALSE, IBM, AMIGA, 8, ""
  48. };
  49.  
  50. AGLOBAL struct Gadget* eol_gadgets[GIDS_7 + 1];
  51.  
  52. MODULE STRPTR EOLOptions[4] =
  53. {   (STRPTR) "LF    (Amiga)",
  54.     (STRPTR) "CR    (Macintosh)",
  55.     (STRPTR) "CR+LF (IBM-PC)",
  56.     NULL
  57. };
  58.  
  59. MODULE ABOOL spaceeol(TEXT nextchar);
  60.  
  61. AGLOBAL void eol1(void)
  62. {   struct Hook Hook7Struct;
  63.  
  64.     /* Create the window object. */
  65.     lockscreen();
  66.     gadtools();
  67.     InitHook(&Hook7Struct, Hook7Func, NULL);
  68.     if (!(WinObject[7] =          NewObject(WINDOW_GetClass(), NULL,
  69.     // window
  70.     WA_PubScreen,                 ScreenPtr,
  71.     WA_ScreenTitle,               "Report+",
  72.     WA_Title,                     "Report+: EOL/Tab Converter",
  73.     WA_Activate,                  TRUE,
  74.     WA_DepthGadget,               TRUE,
  75.     WA_DragBar,                   TRUE,
  76.     WA_CloseGadget,               TRUE,
  77.     WA_SizeGadget,                TRUE,
  78.     WA_IDCMP,                     IDCMP_RAWKEY,
  79.     WINDOW_IDCMPHook,             &Hook7Struct,
  80.     WINDOW_IDCMPHookBits,         IDCMP_RAWKEY,
  81.     WINDOW_MenuStrip,             MenuPtr,
  82.     WINDOW_Position,              WPOS_CENTERSCREEN,
  83.     WINDOW_ParentGroup,           eol_gadgets[GID_7_LY1] =
  84.                                   NewObject(LAYOUT_GetClass(), NULL,
  85.         // root-layout
  86.         LAYOUT_Orientation,       LAYOUT_ORIENT_VERT,
  87.         LAYOUT_SpaceOuter,        TRUE,
  88.         LAYOUT_DeferLayout,       TRUE,
  89.         LAYOUT_AddChild,
  90.         NewObject
  91.         (   LAYOUT_GetClass(),    NULL,
  92.             LAYOUT_Orientation,   LAYOUT_ORIENT_HORIZ,
  93.             LAYOUT_SpaceOuter,    TRUE,
  94.             LAYOUT_VertAlignment, LALIGN_CENTER,
  95.             LAYOUT_HorizAlignment,LALIGN_CENTER,
  96.             LAYOUT_BevelStyle,    BVS_NONE,
  97.             LAYOUT_AddChild,
  98.             NewObject
  99.             (   LAYOUT_GetClass(),    NULL,
  100.                 LAYOUT_Orientation,   LAYOUT_ORIENT_VERT,
  101.                 LAYOUT_SpaceOuter,    TRUE,
  102.                 LAYOUT_VertAlignment, LALIGN_CENTER,
  103.                 LAYOUT_HorizAlignment,LALIGN_CENTER,
  104.                 LAYOUT_BevelStyle,    BVS_FIELD,
  105.                 LAYOUT_AddImage,          NewObject
  106.                 (   LABEL_GetClass(),     NULL,
  107.                     LABEL_Text,           "_Source:",
  108.                     LABEL_Justification,  LJ_CENTER,
  109.                 TAG_END),
  110.                 CHILD_WeightedHeight,     0,
  111.                 LAYOUT_AddChild,          eol_gadgets[GID_7_RA1] =
  112.                 NewObject
  113.                 (   RADIOBUTTON_GetClass(),NULL,
  114.                     GA_ID,                GID_7_RA1,
  115.                     GA_RelVerify,         TRUE,
  116.                     GA_Text,              EOLOptions,
  117.                     RADIOBUTTON_Selected, (WORD) eol.source,
  118.                 TAG_END),
  119.             TAG_END),
  120.             CHILD_WeightedWidth,      50,
  121.             LAYOUT_AddChild,
  122.             NewObject
  123.             (   LAYOUT_GetClass(),    NULL,
  124.                 LAYOUT_Orientation,   LAYOUT_ORIENT_VERT,
  125.                 LAYOUT_SpaceOuter,    TRUE,
  126.                 LAYOUT_VertAlignment, LALIGN_CENTER,
  127.                 LAYOUT_HorizAlignment,LALIGN_CENTER,
  128.                 LAYOUT_BevelStyle,    BVS_FIELD,
  129.                 LAYOUT_AddImage,          NewObject
  130.                 (   LABEL_GetClass(),     NULL,
  131.                     LABEL_Text,           "_Destination:",
  132.                     LABEL_Justification,  LJ_CENTER,
  133.                 TAG_END),
  134.                 CHILD_WeightedHeight,     0,
  135.                 LAYOUT_AddChild,          eol_gadgets[GID_7_RA2] =
  136.                 NewObject
  137.                 (   RADIOBUTTON_GetClass(),NULL,
  138.                     GA_ID,                GID_7_RA2,
  139.                     GA_RelVerify,         TRUE,
  140.                     GA_Text,              EOLOptions,
  141.                     RADIOBUTTON_Selected, (WORD) eol.dest,
  142.                 TAG_END),
  143.             TAG_END),
  144.             CHILD_WeightedWidth,      50,
  145.         TAG_END),
  146.         LAYOUT_AddChild,
  147.         NewObject
  148.         (   LAYOUT_GetClass(),    NULL,
  149.             LAYOUT_Orientation,   LAYOUT_ORIENT_HORIZ,
  150.             LAYOUT_SpaceOuter,    TRUE,
  151.             LAYOUT_VertAlignment, LALIGN_CENTER,
  152.             LAYOUT_HorizAlignment,LALIGN_CENTER,
  153.             LAYOUT_BevelStyle,    BVS_NONE,
  154.             LAYOUT_AddChild,          eol_gadgets[GID_7_CB1] =
  155.             NewObject
  156.             (   CHECKBOX_GetClass(),  NULL,
  157.                 GA_ID,                GID_7_CB2,
  158.                 GA_RelVerify,         TRUE,
  159.                 GA_Text,              "C_onvert tabs to spaces?",
  160.                 GA_Selected,          (BOOL) eol.detabulate,
  161.             TAG_END),
  162.             CHILD_WeightedWidth,      0,
  163.             LAYOUT_AddImage,
  164.             NewObject
  165.             (   LABEL_GetClass(),     NULL,
  166.                 LABEL_Text,           "",
  167.             TAG_END),
  168.             CHILD_WeightedWidth,      100,
  169.             LAYOUT_AddImage,
  170.             NewObject
  171.             (   LABEL_GetClass(),     NULL,
  172.                 LABEL_Text,           "_Tab size:",
  173.             TAG_END),
  174.             CHILD_WeightedWidth,      0,
  175.             LAYOUT_AddChild,          eol_gadgets[GID_7_IN1] =
  176.             NewObject
  177.             (   INTEGER_GetClass(),   NULL,
  178.                 GA_ID,                GID_7_IN1,
  179.                 GA_RelVerify,         TRUE,
  180.                 GA_TabCycle,          TRUE,
  181.                 INTEGER_Number,       eol.tabsize,
  182.                 INTEGER_Minimum,      0,
  183.                 INTEGER_Maximum,      99,
  184.                 INTEGER_MinVisible,   2,
  185.             TAG_END),
  186.             CHILD_WeightedWidth,      0,
  187.         TAG_END), 
  188.         CHILD_WeightedHeight,         0,
  189.         LAYOUT_AddChild,              eol_gadgets[GID_7_CB2] =
  190.         NewObject
  191.         (   CHECKBOX_GetClass(),      NULL,
  192.             GA_ID,                    GID_7_CB2,
  193.             GA_RelVerify,             TRUE,
  194.             GA_Text,                  "_Unwrap words?",
  195.             GA_Selected,              (BOOL) eol.unwrap,
  196.         TAG_END),
  197.         CHILD_WeightedHeight,         0,
  198.         LAYOUT_AddChild,
  199.         NewObject
  200.         (   LAYOUT_GetClass(),        NULL,
  201.             LAYOUT_Orientation,       LAYOUT_ORIENT_HORIZ,
  202.             LAYOUT_SpaceOuter,        TRUE,
  203.             LAYOUT_VertAlignment, LALIGN_CENTER,
  204.             LAYOUT_HorizAlignment,LALIGN_CENTER,
  205.             LAYOUT_BevelStyle,    BVS_FIELD,
  206.             LAYOUT_AddImage,
  207.             NewObject
  208.             (   LABEL_GetClass(),     NULL,
  209.                 LABEL_Text,       "_Pathname(s):",
  210.                 LABEL_Justification,LJ_LEFT,
  211.             TAG_END),
  212.             LAYOUT_AddChild,      eol_gadgets[GID_7_ST1] =
  213.             NewObject
  214.             (   STRING_GetClass(), NULL,
  215.                 GA_ID,            GID_7_ST1,
  216.                 GA_RelVerify,     TRUE,
  217.                 STRINGA_TextVal,  eol.pathname,
  218.                 STRINGA_MinVisible,20,
  219.             TAG_END),
  220.             LAYOUT_AddChild,      eol_gadgets[GID_7_BU1] =
  221.             NewObject
  222.             (   NULL, "button.gadget",
  223.                 GA_ID,            GID_7_BU1,
  224.                 GA_RelVerify,     TRUE,
  225.                 BUTTON_AutoButton,BAG_POPFILE,
  226.             TAG_END),
  227.             CHILD_WeightedWidth,  0,
  228.         TAG_END),
  229.         CHILD_WeightedHeight,     0,
  230.         LAYOUT_AddChild,          eol_gadgets[GID_7_ST2] =
  231.                                   NewObject(STRING_GetClass(), NULL,
  232.             GA_ReadOnly,          TRUE,
  233.             GA_ID,                GID_7_ST2,
  234.             STRINGA_TextVal,      "Ready.",
  235.         TAG_END),
  236.         CHILD_WeightedHeight,     0,
  237.         LAYOUT_AddChild,
  238.         NewObject
  239.         (   LAYOUT_GetClass(),    NULL,
  240.             LAYOUT_Orientation,   LAYOUT_ORIENT_HORIZ,
  241.             LAYOUT_SpaceOuter,    TRUE,
  242.             LAYOUT_VertAlignment, LALIGN_CENTER,
  243.             LAYOUT_HorizAlignment,LALIGN_CENTER,
  244.             LAYOUT_BevelStyle,    BVS_NONE,
  245.             LAYOUT_AddChild,      eol_gadgets[GID_7_BU3] =
  246.                                   NewObject(NULL, "button.gadget",
  247.                 GA_ID,            GID_7_BU3,
  248.                 GA_RelVerify,     TRUE,
  249.                 GA_Text,          "Pro_cess",
  250.             TAG_END),
  251.             CHILD_WeightedWidth,  50,
  252.             LAYOUT_AddChild,      eol_gadgets[GID_7_BU4] =
  253.                                   NewObject(NULL, "button.gadget",
  254.                 GA_ID,            GID_7_BU4,
  255.                 GA_RelVerify,     TRUE,
  256.                 GA_Text,          "Stop",
  257.                 GA_Disabled,      TRUE,
  258.             TAG_END),
  259.             CHILD_WeightedWidth,  50,
  260.         TAG_END),
  261.         CHILD_WeightedHeight,     0,
  262.     TAG_END)
  263.     )))
  264.     {   rq("Can't create ReAction objects!");
  265.     }
  266.     unlockscreen();
  267.     openwindow();
  268.     ActivateLayoutGadget(eol_gadgets[GID_7_LY1], MainWindowPtr, NULL, (Object) eol_gadgets[GID_7_ST1]);
  269.  
  270.     loop();
  271.     closewindow();
  272. }
  273.  
  274. AGLOBAL void eol_do(void)
  275. {   STRPTR stringptr;
  276.  
  277.     if (!(GetAttr
  278.     (   STRINGA_TextVal, eol_gadgets[GID_7_ST1], (ULONG *) &stringptr
  279.     )))
  280.     {   rq("Unsupported inquiry!"); // should never happen
  281.     }
  282.     strcpy(eol.pathname, stringptr);
  283.     if (!(GetAttr
  284.     (   INTEGER_Number, eol_gadgets[GID_7_IN1], (ULONG *) &eol.tabsize
  285.     )))
  286.     {   rq("Unsupported inquiry!"); // should never happen
  287.     }
  288.  
  289.     SetGadgetAttrs
  290.     (   eol_gadgets[GID_7_BU4], MainWindowPtr, NULL,
  291.         GA_Disabled, FALSE,
  292.     TAG_END);
  293.     SetGadgetAttrs
  294.     (   eol_gadgets[GID_7_RA1], MainWindowPtr, NULL,
  295.         GA_Disabled, TRUE,
  296.     TAG_END);
  297.     SetGadgetAttrs
  298.     (   eol_gadgets[GID_7_RA2], MainWindowPtr, NULL,
  299.         GA_Disabled, TRUE,
  300.     TAG_END);
  301.     SetGadgetAttrs
  302.     (   eol_gadgets[GID_7_ST1], MainWindowPtr, NULL,
  303.         GA_Disabled, TRUE,
  304.     TAG_END);
  305.     SetGadgetAttrs
  306.     (   eol_gadgets[GID_7_BU1], MainWindowPtr, NULL,
  307.         GA_Disabled, TRUE,
  308.     TAG_END);
  309.     SetGadgetAttrs
  310.     (   eol_gadgets[GID_7_CB1], MainWindowPtr, NULL,
  311.         GA_Disabled, TRUE,
  312.     TAG_END);
  313.     SetGadgetAttrs
  314.     (   eol_gadgets[GID_7_CB2], MainWindowPtr, NULL,
  315.         GA_Disabled, TRUE,
  316.     TAG_END);
  317.     SetGadgetAttrs
  318.     (   eol_gadgets[GID_7_IN1], MainWindowPtr, NULL,
  319.         GA_Disabled, TRUE,
  320.     TAG_END);
  321.     SetGadgetAttrs
  322.     (   eol_gadgets[GID_7_BU3], MainWindowPtr, NULL,
  323.         GA_Disabled, TRUE,
  324.     TAG_END);
  325.  
  326.     strcpy(shared.pathname, eol.pathname);
  327.     convert(TRUE);
  328.     strcpy(eol.pathname, shared.pathname);
  329.  
  330.     if (!stop)
  331.     {   SetGadgetAttrs
  332.         (   eol_gadgets[GID_7_ST2], MainWindowPtr, NULL,
  333.             STRINGA_TextVal, "All done.",
  334.         TAG_END);
  335.     }
  336.     SetGadgetAttrs
  337.     (   eol_gadgets[GID_7_BU4], MainWindowPtr, NULL,
  338.         GA_Disabled, TRUE,
  339.     TAG_END);
  340.     SetGadgetAttrs
  341.     (   eol_gadgets[GID_7_RA1], MainWindowPtr, NULL,
  342.         GA_Disabled, FALSE,
  343.     TAG_END);
  344.     SetGadgetAttrs
  345.     (   eol_gadgets[GID_7_RA2], MainWindowPtr, NULL,
  346.         GA_Disabled, FALSE,
  347.     TAG_END);
  348.     SetGadgetAttrs
  349.     (   eol_gadgets[GID_7_ST1], MainWindowPtr, NULL,
  350.         GA_Disabled, FALSE,
  351.     TAG_END);
  352.     SetGadgetAttrs
  353.     (   eol_gadgets[GID_7_BU1], MainWindowPtr, NULL,
  354.         GA_Disabled, FALSE,
  355.     TAG_END);
  356.     SetGadgetAttrs
  357.     (   eol_gadgets[GID_7_CB1], MainWindowPtr, NULL,
  358.         GA_Disabled, FALSE,
  359.     TAG_END);
  360.     SetGadgetAttrs
  361.     (   eol_gadgets[GID_7_CB2], MainWindowPtr, NULL,
  362.         GA_Disabled, FALSE,
  363.     TAG_END);
  364.     SetGadgetAttrs
  365.     (   eol_gadgets[GID_7_IN1], MainWindowPtr, NULL,
  366.         GA_Disabled, FALSE,
  367.     TAG_END);
  368.     SetGadgetAttrs
  369.     (   eol_gadgets[GID_7_BU3], MainWindowPtr, NULL,
  370.         GA_Disabled, FALSE,
  371.     TAG_END);
  372. }
  373.  
  374. AGLOBAL void eolconvert(ABOOL gui)
  375. {   ULONG                gap, i, j, cursorx = 0;
  376.     ABOOL                ok                 = TRUE;
  377.     struct FileInfoBlock InputInfoBlock;
  378.     UBYTE*               InputBufferPtr; // always use UBYTE not APTR for pointer arithmetic
  379.     BPTR                 FileHandle;
  380.     TEXT                 saystring[VLONGFIELD + 1];
  381.  
  382.     strcpy(saystring, "Converting ");
  383.     strcat(saystring, shared.thisfile);
  384.     strcat(saystring, "...");
  385.     if (gui)
  386.     {   SetGadgetAttrs
  387.         (   eol_gadgets[GID_7_ST2], MainWindowPtr, NULL,
  388.             STRINGA_TextVal, saystring,
  389.         TAG_END);
  390.     } else
  391.     {   Printf("%s", saystring);
  392.         Flush(Output());
  393.     }
  394.  
  395.     if (FileHandle = (BPTR) Lock(shared.thisfile, ACCESS_READ))
  396.     {   if (Examine(FileHandle, &InputInfoBlock))
  397.         {   UnLock(FileHandle);
  398.             // FileHandle = NULL;
  399.             if (InputInfoBlock.fib_DirEntryType == -3) // if a file
  400.             {   // if it is a directory, we would ideally like to convert all
  401.                 // files in that directory. We also should support links.
  402.                 if (InputBufferPtr = AllocMem(InputInfoBlock.fib_Size, MEMF_ANY | MEMF_PUBLIC))
  403.                 {   if (FileHandle = (BPTR) Open(shared.thisfile, MODE_OLDFILE))
  404.                     {   if (Read(FileHandle, InputBufferPtr, InputInfoBlock.fib_Size) != -1)
  405.                         {   Close(FileHandle);
  406.                             if (FileHandle = (BPTR) Open(shared.thisfile, MODE_NEWFILE))
  407.                             {   for (i = 0; i < InputInfoBlock.fib_Size; i++)
  408.                                 {   if (*(InputBufferPtr + i) == LF)
  409.                                     {   if (eol.unwrap && (eol.source == AMIGA || eol.source == IBM) && spaceeol(*(InputBufferPtr + i + 1)))
  410.                                         {   cursorx++;
  411.                                             FPutC(FileHandle, ' ');
  412.                                         } else
  413.                                         {   cursorx = 0;
  414.  
  415.                                             if (eol.source == eol.dest)
  416.                                                 FPutC(FileHandle, LF); // pass it through
  417.                                             elif (eol.source == AMIGA && eol.dest == IBM)
  418.                                             {   FPutC(FileHandle, CR); // add this
  419.                                                 FPutC(FileHandle, LF); // and pass this through
  420.                                             } elif (eol.source == AMIGA && eol.dest == MAC)
  421.                                                 FPutC(FileHandle, CR); // convert from LF to CR
  422.                                             elif (eol.source == IBM && eol.dest == AMIGA)
  423.                                                 FPutC(FileHandle, LF); // pass it through
  424.                                             elif (eol.source == IBM && eol.dest == MAC)
  425.                                                 ; // do nothing
  426.                                             else ; // mac as source: we never expect LFs
  427.                                     }   }
  428.                                     elif (*(InputBufferPtr + i) == CR)
  429.                                     {   if (eol.unwrap && eol.source == MAC && spaceeol(*(InputBufferPtr + i + 1)))
  430.                                         {   cursorx++;
  431.                                             FPutC(FileHandle, ' ');
  432.                                         } else
  433.                                         {   cursorx = 0;
  434.  
  435.                                             if (eol.source == eol.dest)
  436.                                                 FPutC(FileHandle, CR); // pass it through
  437.                                             elif (eol.source == IBM && eol.dest == AMIGA)
  438.                                                 ; // do nothing
  439.                                             elif (eol.source == IBM && eol.dest == MAC)
  440.                                                 FPutC(FileHandle, CR); // pass it through
  441.                                             elif (eol.source == MAC && eol.dest == AMIGA)
  442.                                                 FPutC(FileHandle, LF); // convert from CR to LF
  443.                                             elif (eol.source == MAC && eol.dest == IBM)
  444.                                             {   FPutC(FileHandle, CR); // pass this through
  445.                                                 FPutC(FileHandle, LF); // and add this
  446.                                             } else ; // amiga as source: we never expect CRs
  447.                                     }   }
  448.                                     elif (*(InputBufferPtr + i) == TAB)
  449.                                     {   if (eol.detabulate)
  450.                                         {   gap = (((cursorx / eol.tabsize) + 1) * eol.tabsize) - cursorx;
  451.                                             for (j = 1; j <= gap; j++)
  452.                                                 FPutC(FileHandle, ' ');
  453.                                             cursorx += gap;
  454.                                         } else FPutC(FileHandle, TAB); // no point to cursorx in non-detabulate
  455.                                     } else
  456.                                     {   FPutC(FileHandle, *(InputBufferPtr + i));
  457.                                         cursorx++;
  458.                                 }   }
  459.                                 /* Note that FPutC() returns EOF for errors; this is not currently
  460.                                 checked. */
  461.                                 ok = TRUE;
  462.                                 Close(FileHandle);
  463.                         }   }
  464.                         else
  465.                         {   Close(FileHandle);
  466.                     }   }
  467.                     FreeMem(InputBufferPtr, InputInfoBlock.fib_Size);
  468.         }   }   }
  469.         else
  470.         {   UnLock(FileHandle);
  471.     }   }
  472.  
  473.     if (gui)
  474.     {   if (ok)
  475.             strcat(saystring, "done.");
  476.         else strcat(saystring, "failed!");
  477.  
  478.         SetGadgetAttrs
  479.         (   eol_gadgets[GID_7_ST2], MainWindowPtr, NULL,
  480.             STRINGA_TextVal, saystring,
  481.         TAG_END);
  482.     } else
  483.     {   if (ok)
  484.             Printf("done.\n");
  485.         else Printf("failed!\n");
  486.     }
  487.  
  488.     checkabort(gui);
  489. }
  490.  
  491. AGLOBAL void eol_loop(ULONG gid)
  492. {   STRPTR stringptr;
  493.  
  494.     switch(gid)
  495.     {
  496.     case GID_7_RA1:
  497.         if (!(GetAttr
  498.         (   RADIOBUTTON_Selected, eol_gadgets[GID_7_RA1], (ULONG *) &eol.source
  499.         )))
  500.         {   rq("Unsupported inquiry!"); // should never happen
  501.         }
  502.     break;
  503.     case GID_7_RA2:
  504.         if (!(GetAttr
  505.         (   RADIOBUTTON_Selected, eol_gadgets[GID_7_RA2], (ULONG *) &eol.dest
  506.         )))
  507.         {   rq("Unsupported inquiry!"); // should never happen
  508.         }
  509.     break;
  510.     case GID_7_ST1:
  511.         if (!(GetAttr
  512.         (   STRINGA_TextVal, eol_gadgets[GID_7_ST1], (ULONG *) &stringptr
  513.         )))
  514.         {   rq("Unsupported inquiry!"); // should never happen
  515.         }
  516.         strcpy(eol.pathname, stringptr);
  517.     break;
  518.     case GID_7_BU1:
  519.         strcpy(shared.pathname, eol.pathname);
  520.         multiasl("#?.info");
  521.         strcpy(eol.pathname, shared.pathname);
  522.         SetGadgetAttrs
  523.         (   eol_gadgets[GID_7_ST1], MainWindowPtr, NULL,
  524.             STRINGA_TextVal, eol.pathname,
  525.             TAG_END
  526.         );
  527.     break;
  528.     case GID_7_BU3:
  529.         eol_do();
  530.     break;
  531.     case GID_7_CB1:
  532.         if (!(GetAttr
  533.         (   GA_Selected, eol_gadgets[GID_7_CB1], (ULONG *) &eol.detabulate
  534.         )))
  535.         {   rq("Unsupported inquiry!"); // should never happen
  536.         }
  537.     break;
  538.     case GID_7_CB2:
  539.         if (!(GetAttr
  540.         (   GA_Selected, eol_gadgets[GID_7_CB2], (ULONG *) &eol.unwrap
  541.         )))
  542.         {   rq("Unsupported inquiry!"); // should never happen
  543.         }
  544.     break;
  545.     case GID_7_IN1:
  546.         if (!(GetAttr
  547.         (   INTEGER_Number, eol_gadgets[GID_7_IN1], (ULONG *) &eol.tabsize
  548.         )))
  549.         {   rq("Unsupported inquiry!"); // should never happen
  550.         }
  551.     break;
  552.     default:
  553.     break;
  554. }   }
  555.  
  556. MODULE ABOOL spaceeol(TEXT nextchar)
  557. {   if
  558.     (   nextchar == ' '
  559.      || nextchar == TAB
  560.      || nextchar == LF
  561.      || nextchar == CR
  562.     )
  563.     {   return(FALSE);
  564.     } else return(TRUE);
  565. }
  566.  
  567. AGLOBAL void eol_die(void)
  568. {   IOBuffer[1] = (UBYTE) eol.source;
  569.     IOBuffer[2] = (UBYTE) eol.dest;
  570.     IOBuffer[3] = (UBYTE) eol.detabulate;
  571.     IOBuffer[4] = (UBYTE) eol.tabsize;
  572.     IOBuffer[5] = (UBYTE) eol.unwrap;
  573. }
  574.  
  575. AGLOBAL void eol_config(void)
  576. {   eol.source     = (ULONG) IOBuffer[1];
  577.     eol.dest       = (ULONG) IOBuffer[2];
  578.     eol.detabulate = (ULONG) IOBuffer[3];
  579.     eol.tabsize    = (ULONG) IOBuffer[4];
  580.     eol.unwrap     = (ULONG) IOBuffer[5];
  581. }
  582.  
  583. AGLOBAL ULONG Hook7Func(struct Hook *h, VOID *o, VOID *msg)
  584. {   /* "When the hook is called, the data argument points to the 
  585.     window object and message argument to the IntuiMessage." */
  586.  
  587.     UWORD code, qual;
  588.  
  589.     geta4(); // wait till here before doing anything
  590.  
  591.     code = ((struct IntuiMessage *) msg)->Code;
  592.     qual = ((struct IntuiMessage *) msg)->Qualifier;
  593.  
  594.     switch(code)
  595.     {
  596.     case SCAN_HELP:
  597.         helpabout();
  598.     break;
  599.     case SCAN_ESCAPE:
  600.         if ((qual & IEQUALIFIER_LSHIFT) || (qual & IEQUALIFIER_RSHIFT))
  601.         {   cleanexit(EXIT_SUCCESS);
  602.         } else page = 0;
  603.     break;
  604.     case SCAN_D:
  605.         if (!(qual & IEQUALIFIER_LSHIFT) && !(qual & IEQUALIFIER_RSHIFT))
  606.         {   if (eol.dest < 2)
  607.                 eol.dest++;
  608.             else eol.dest = 0;
  609.         } else
  610.         {   if (eol.dest > 0)
  611.                 eol.dest--;
  612.             else eol.dest = 2;
  613.         }
  614.         SetGadgetAttrs
  615.         (   eol_gadgets[GID_7_RA2], MainWindowPtr, NULL,
  616.             RADIOBUTTON_Selected, eol.dest,
  617.         TAG_END);
  618.         // we must explicitly refresh
  619.         RefreshGadgets((struct Gadget *) eol_gadgets[GID_7_RA2], MainWindowPtr, NULL);
  620.     break;
  621.     case SCAN_O:
  622.         // the gadget is handled automatically by the system, all we need
  623.         // to do is update our internal record of the state of the gadget
  624.         if (!(GetAttr
  625.         (   GA_Selected, eol_gadgets[GID_7_CB1], (ULONG *) &eol.detabulate
  626.         )))
  627.         {   rq("Unsupported inquiry!"); // should never happen
  628.         }
  629.     break;
  630.     case SCAN_P:
  631.         ActivateLayoutGadget(eol_gadgets[GID_7_LY1], MainWindowPtr, NULL, (Object) eol_gadgets[GID_7_ST1]);
  632.     break;
  633.     case SCAN_S:
  634.         if (!(qual & IEQUALIFIER_LSHIFT) && !(qual & IEQUALIFIER_RSHIFT))
  635.         {   if (eol.source < 2)
  636.                 eol.source++;
  637.             else eol.source = 0;
  638.         } else
  639.         {   if (eol.source > 0)
  640.                 eol.source--;
  641.             else eol.source = 2;
  642.         }
  643.         SetGadgetAttrs
  644.         (   eol_gadgets[GID_7_RA1], MainWindowPtr, NULL,
  645.             RADIOBUTTON_Selected, eol.source,
  646.         TAG_END);
  647.  
  648.         // we must explicitly refresh
  649.         RefreshGadgets((struct Gadget *) eol_gadgets[GID_7_RA1], MainWindowPtr, NULL);
  650.     break;
  651.     case SCAN_T:
  652.         ActivateLayoutGadget(eol_gadgets[GID_7_LY1], MainWindowPtr, NULL, (Object) eol_gadgets[GID_7_IN1]);
  653.     break;
  654.     case SCAN_U:
  655.         // the gadget is handled automatically by the system, all we need
  656.         // to do is update our internal record of the state of the gadget
  657.         if (!(GetAttr
  658.         (   GA_Selected, eol_gadgets[GID_7_CB2], (ULONG *) &eol.unwrap
  659.         )))
  660.         {   rq("Unsupported inquiry!"); // should never happen
  661.         }
  662.     break;
  663.     case SCAN_PERIOD:
  664.         strcpy(shared.pathname, eol.pathname);
  665.         multiasl("~(#?.info)");
  666.         strcpy(eol.pathname, shared.pathname);
  667.         SetGadgetAttrs
  668.         (   eol_gadgets[GID_7_ST1], MainWindowPtr, NULL,
  669.             STRINGA_TextVal, eol.pathname,
  670.         TAG_END);
  671.     break;
  672.     default:
  673.     break;
  674.     }
  675.  
  676.     return(1);
  677. }
  678.  
  679.  
  680.